import variables from '@/assets/styles/element-variables.scss'
import defaultSettings from '@/settings'

const {
  sideTheme,
  showSettings,
  tagsView,
  fixedHeader,
  sidebarLogo,
  layoutMode,
  layoutTheme,
  topBarOut
} = defaultSettings

const state = {
  theme: variables.theme,
  sideTheme: sideTheme,
  showSettings: showSettings,
  tagsView: tagsView,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo,
  layoutMode: layoutMode,
  layoutTheme: layoutTheme,
  topBarOut: topBarOut
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    if (Object.prototype.hasOwnProperty.call(state, key)) {
      state[key] = value
    }
    if (key === 'topBarOut') {
      document
        .getElementsByTagName('body')[0]
        .style.setProperty('--topBarOutHeight', value ? '50px' : '0px')
    }
  }
}

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
